package cn.gson.springboot.controller;

import cn.gson.springboot.model.pojos.Employee;
import cn.gson.springboot.model.pojos.Purchase;
import cn.gson.springboot.model.service.PurchaseService;
import cn.gson.springboot.model.vo.PurchaseVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class PurchaseController {
    @Autowired
    PurchaseService purService;
    @Autowired
    HttpSession session;

    // 查询采购单集合-分页
    @RequestMapping("/pur-list")
    @ResponseBody
    public Map<String,Object> purchaseList(Integer page,Integer size,Integer value,Integer num,String purTheme){
        Page<Object> objects = PageHelper.startPage(page, size);
        List<Purchase> pur= purService.selectPurchase(value,num,purTheme);
        Map<String,Object> map = new HashMap<>();
        map.put("total",objects.getTotal());
        map.put("rows",pur);
        return map;
    }
    // 查询采购单集合
    @RequestMapping("/pur-all-list")
    @ResponseBody
    public List<Purchase> purchaseAllList(){
        List<Purchase> pur= purService.selectPurchase(0,0,"");
        return pur;
    }
    // 按客户ID查询审核通过的采购单
    @RequestMapping("/pur-cus-list")
    @ResponseBody
    public List<Purchase> selectCusPurchase(Integer cusId){
        List<Purchase> purchases = purService.selectCusPurchase(cusId);
        return purchases;
    }
    // 按采购Id查询
    @RequestMapping("/pur-id")
    @ResponseBody
    public Purchase purchaseById(Integer purId){
        Purchase pur= purService.selectPurchaseById(purId);
        return pur;
    }
    // 按采购单号查询
    @RequestMapping("/pur-no")
    @ResponseBody
    public Purchase selectPurchaseByPurNo(String purNo){
        Purchase pur= purService.selectPurchaseByPurNo(purNo);
        return pur;
    }
    // 查询未完成的采购
    @RequestMapping("/pur-implement-list")
    @ResponseBody
    public List<Purchase> selectPurchaseImplement(){
        List<Purchase> pur= purService.selectPurchaseImplement();
        return pur;
    }
    // 查询过去30天完成的采购
    @RequestMapping("/pur-past-thirty-list")
    @ResponseBody
    public List<Purchase> purchasePastThirtyList(){
        List<Purchase> pur= purService.selectPurchasePastThirty();
        return pur;
    }
    // 查询未尽付款的采购
    @RequestMapping("/pur-not-payment-list")
    @ResponseBody
    public List<Purchase> selectPurchaseNotPayment(){
        List<Purchase> pur= purService.selectPurchaseNotPayment();
        return pur;
    }
    // 计算采购数量分类分布
    @RequestMapping("/compute-pur-num-sort")
    @ResponseBody
    public List<Map<String,Object>> computePurchaseNumBySort(){
        List<Map<String, Object>> maps = purService.computePurchaseNumBySort();
        return maps;
    }
    // 计算采购合约数量对应客户
    @RequestMapping("/compute-pur-num-sing-cus")
    @ResponseBody
    public List<Map<String,Object>> computePurchaseNumBySigningByCus(){
        List<Map<String, Object>> maps = purService.computePurchaseNumBySigningByCus();
        return maps;
    }
    // 计算采购单数量月度统计
    @RequestMapping("/compute-pur-num-month")
    @ResponseBody
    public List<Map<String,Object>> computePurchaseNumByMonth(){
        List<Map<String, Object>> maps = purService.computePurchaseNumByMonth();
        return maps;
    }
    // 计算采购金额月度统计
    @RequestMapping("/compute-pur-amount-month")
    @ResponseBody
    public List<Map<String,Object>> computePurchaseAmountByMonth(){
        List<Map<String, Object>> maps = purService.computePurchaseAmountByMonth();
        return maps;
    }
    // 计算采购产品金额分布
    @RequestMapping("/compute-pro-amount")
    @ResponseBody
    public List<Map<String,Object>> computeProdDetailAmountByPro(){
        List<Map<String, Object>> maps = purService.computeProdDetailAmountByPro();
        return maps;
    }
    // 计算采购产品数量分布
    @RequestMapping("/compute-pro-num")
    @ResponseBody
    public List<Map<String,Object>> computeProdDetailNumByPro(){
        List<Map<String, Object>> maps = purService.computeProdDetailNumByPro();
        return maps;
    }
    // 计算付款计划数量采购单
    @RequestMapping("/compute-pay-plan-num-pur")
    @ResponseBody
    public List<Map<String,Object>> computePaymentPlanNumByPur(){
        List<Map<String, Object>> maps = purService.computePayPlanNumByPur();
        return maps;
    }
    // 计算付款计划金额采购单
    @RequestMapping("/compute-pay-plan-amount-pur")
    @ResponseBody
    public List<Map<String,Object>> computePayPlanAmountByPur(){
        List<Map<String, Object>> maps = purService.computePayPlanAmountByPur();
        return maps;
    }
    // 计算应付款金额对应客户分布
    @RequestMapping("/compute-pay-plan-amount-wf-cus")
    @ResponseBody
    public List<Map<String,Object>> computePayPlanAmountStaByCus(){
        List<Map<String, Object>> maps = purService.computePayPlanAmountStaByCus();
        return maps;
    }
    // 计算付款计划人员数量
    @RequestMapping("/compute-pay-plan-num-emp")
    @ResponseBody
    public List<Map<String,Object>> computePayPlanNumByEmp(){
        List<Map<String, Object>> maps = purService.computePayPlanNumByEmp();
        return maps;
    }
    // 计算付款计划金额人员
    @RequestMapping("/compute-pay-plan-amount-emp")
    @ResponseBody
    public List<Map<String,Object>> computePayPlanAmountByEmp(){
        List<Map<String, Object>> maps = purService.computePayPlanAmountByEmp();
        return maps;
    }
    // 计算付款计划金额月度
    @RequestMapping("/compute-pay-plan-amount-month")
    @ResponseBody
    public List<Map<String,Object>> computePayPlanAmountByMonth(){
        List<Map<String, Object>> maps = purService.computePayPlanAmountByMonth();
        return maps;
    }
    // 计算付款记录金额采购单
    @RequestMapping("/compute-pay-records-amount-pur")
    @ResponseBody
    public List<Map<String,Object>> computePayRecordsAmountByPur(){
        List<Map<String, Object>> maps = purService.computePayRecordsAmountByPur();
        return maps;
    }
    // 计算付款记录金额人员
    @RequestMapping("/compute-pay-records-amount-emp")
    @ResponseBody
    public List<Map<String,Object>> computePayRecordsAmountByEmp(){
        List<Map<String, Object>> maps = purService.computePayRecordsAmountByEmp();
        return maps;
    }
    // 计算付款记录金额月度
    @RequestMapping("/compute-pay-records-amount-month")
    @ResponseBody
    public List<Map<String,Object>> computePayRecordsAmountByMonth(){
        List<Map<String, Object>> maps = purService.computePayRecordsAmountByMonth();
        return maps;
    }
    // 计算付款记录金额分类
    @RequestMapping("/compute-pay-records-amount-classify")
    @ResponseBody
    public List<Map<String,Object>> computePayRecordsAmountByClassify(){
        List<Map<String, Object>> maps = purService.computePayRecordsAmountByClassify();
        return maps;
    }
    // 计算采购发票金额采购单
    @RequestMapping("/compute-pay-invoice-amount-pur")
    @ResponseBody
    public List<Map<String,Object>> computePayInvoiceAmountByPur(){
        List<Map<String, Object>> maps = purService.computePayInvoiceAmountByPur();
        return maps;
    }
    // 计算采购发票金额人员
    @RequestMapping("/compute-pay-invoice-amount-emp")
    @ResponseBody
    public List<Map<String,Object>> computePayInvoiceAmountByEmp(){
        List<Map<String, Object>> maps = purService.computePayInvoiceAmountByEmp();
        return maps;
    }
    // 计算采购发票金额月度
    @RequestMapping("/compute-pay-invoice-amount-month")
    @ResponseBody
    public List<Map<String,Object>> computePayInvoiceAmountByMonth(){
        List<Map<String, Object>> maps = purService.computePayInvoiceAmountByMonth();
        return maps;
    }
    // 计算采购发票票据类型
    @RequestMapping("/compute-pay-invoice-amount-type")
    @ResponseBody
    public List<Map<String,Object>> computePayInvoiceAmountByPaperType(){
        List<Map<String, Object>> maps = purService.computePayInvoiceAmountByPaperType();
        return maps;
    }
    // 新增采购单
    @PostMapping("/save-purchase")
    @ResponseBody
    public void savePurchase(@RequestBody PurchaseVo vo){
        purService.savePurchase(vo);
    }
    // 删除采购单
    @PostMapping("/delete-purchase")
    @ResponseBody
    public void deletePurchase(@RequestParam(value = "purchaseId") Integer purchaseId){
        purService.deletePurchase(purchaseId);
    }
}
